#include<stdio.h>
#include<stdlib.h>
int v[100];
int e[20][20];
int a;
int b;
int v1, v2;
int c;
int g = 0;
typedef struct {
	int edge1;
	int edge2;
	int weight;
}edg;
edg edge[20];
void Init();
void Sort();
int Find(int d, int* f);
void  Kruska();
int main() {
	Init();
	Kruska();
}
void Init() {
	a = 7;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < a; j++) {
			e[i][j] = 12345;
		}
	}
	e[0][1] = 3;
	e[0][5] = 1;
	e[0][2] = 4;
	e[5][2] = 10;
	e[5][4] = 7;
	e[5][6] = 6;
	e[2][6] = 9;
	e[4][3] = 5;
	e[3][1] = 8;
	e[6][4] = 4;
}
void Sort() {
	int t1, t2;
	for (int i = 0; i < g; i++) {
		for (int j = 0; j < g; j++) {   
			if (edge[i].weight > edge[j].weight) {
				t1 = edge[i].edge1;
				t2 = edge[j].edge1;
				edge[i].edge1 = t2;
				edge[j].edge1 = t1;
				t1 = edge[i].edge2;
				t2 = edge[j].edge2;
				edge[i].edge2 = t2;
				edge[j].edge2 = t1;
				t1 = edge[i].weight;
				t2 = edge[j].weight;
				edge[i].weight = t2;
				edge[j].weight = t1;
			}
		}
	}
	for (int i = 0; i < g; i++) {
		printf("(%d %d) %d\n", edge[i].edge1, edge[i].edge2, edge[i].weight);
	}
}
int Find(int d, int* f) {
	while (f[d] != 0) {
		d = f[d];
	}
	return d;
}
void  Kruska() {
	for (int i = 0; i < 10; i++) {
		for (int j = i; j < 10; j++) {
			if (e[i][j] != 12345) {
				edge[g].edge1 = i;
				edge[g].edge2 = j;
				edge[g].weight = e[i][j];
				g++;
			}
		}
	}
	Sort();
	int f[7] = {};
	int d, h;
	for (int i = 0; i < g; i++) {
		d = Find(edge[i].edge1, &f[0]);
		h = Find(edge[i].edge2, &f[0]);
		if (d != h || d == h == 0) {
			printf("(%d %d) %d\n", edge[i].edge1, edge[i].edge2, edge[i].weight);
			f[d] = h;
		}
	}
}

